/*
 * @Descripttion: 响应客户端对仓库的一些请求
 * @version: 1.0
 * @Author: 自由如风
 * @Date: 2021-05-21 10:20:51
 * @LastEditors: 自由如风
 * @LastEditTime: 2021-05-22 20:08:42
 */

const Router = require('koa-router')

const router = new Router();

const fs = require('fs')

const { Store } = require('weixin-nodejs');
const path = require('path');

/** 获取仓库的所有数据，也就是 Store 的 getAll 方法 */
router.get('/', async (ctx, next) => {
    const openId = ctx.query.openId;
    /** 判断Store文件是否存在 */
    console.log(path.join(Store.path, openId + '.json'));
    if (!fs.existsSync(path.join(Store.path, openId + '.json'))) {
        throw new Error("参数不合法")
    }
    ctx.body = new Store(openId).getAll()
    await next();
})


module.exports = router;